package insight.chain.validation;

import insight.chain.exception.ValidatorException;

/**
 * @author huu
 * @create 2025-08-25-18:51
 */
public class LengthValidatorHandler implements ValidatorHandler{
    private int length;
    public LengthValidatorHandler(int length){
        this.length = length;
    }

    @Override
    public void validate(Object value, ValidatorContext context) {
        if(value instanceof String stringValue){
            if(stringValue.length() != length){
                //throw new ValidatorException("length is not" + length + ", your length is" + stringValue.length());
                context.appendError("length is not" + length + ", your length is" + stringValue.length());
            }
            context.donext(stringValue);
        }
    }
}
